home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / pictetri.src / pictetri / pictetris-src / pictetris.h < prev    next >
C/C++ Source or Header  |  1996-02-10  |  9KB  |  178 lines

  1. /***************************************************************************\
  2. |*                                       *|
  3. |*  pictetris.h: A version of Tetris to run on Linux SVGAlib console.       *|
  4. |*                                       *|
  5. |*  Authors:    Mike Taylor (mirk@uk.ac.warwick.cs) &               *|
  6. |*        Arturo Espinosa (arturo@nuclecu.unam.mx)           *|
  7. |*  Started:    Fri May 26 12:26:05 BST 1989 (tetris for terminals)       *|
  8. |*            Dic 1, 1995 (pictetris)                       *|
  9. |*                                       *|
  10. \***************************************************************************/
  11. /***************************************************************************\
  12. |*                                       *|
  13. |*  The following macro, if defined, causes the exclusive high-score       *|
  14. |*  file-locking to be done using lockf(3) instead of the O_EXCL flag       *|
  15. |*  on open(2).     This means that no temporary file need be created, and       *|
  16. |*  thus, that no write-permission is needed on a lockfile-directory.       *|
  17. |*  This should probably be used in preference to open(O_EXCL) when it       *|
  18. |*  exists and is bugless.  WARNING: on some machines, buggy versions       *|
  19. |*  of lockf(3) can crash the machine, (eg. Sun3/4s running SunOS 4.0.1)   *|
  20. |*                                       *|
  21. \***************************************************************************/
  22.  
  23. #undef LOCKF            /* Use lockf(3) instead of open(O_EXCL) */
  24.  
  25. /***************************************************************************\
  26. |*                                       *|
  27. |*  This section declares the path of the files pictetris will make       *|
  28. |*  refference to.                               *|
  29. |*                                       *|
  30. \***************************************************************************/
  31.  
  32. #define LOCK_FILE    "pictlock"    /* name and path of the lock file */
  33. #define SCORE_FILE    "pictscores"  /* name and path of the scores file */
  34. #define PICLIST_FILE    "pictpiclist" /* name and path of the PCX files */
  35. #define SPRITE_FILE      "pictsprites.spr" /* same for the sprite data file */
  36. #define TITLE_PATH      "." /* use an absolute path with no
  37.                            final /   */
  38.  
  39. /*-------------------------------------------------------------------------*/
  40. /* These constants define the keys for the game. The SCANCODES come in     */
  41. /* the file /usr/include/vgakeyboard.h and the KEY defs come in the file   */
  42. /* /usr/include/jinput.h                                                   */
  43. /*-------------------------------------------------------------------------*/
  44.  
  45. #include <vgakeyboard.h>
  46.  
  47. #define LEFT_KEY    SCANCODE_KEYPAD4    /* Move piece left */
  48. #define RIGHT_KEY    SCANCODE_KEYPAD6    /* Move piece right */
  49. #define ROTATE_KEY    SCANCODE_KEYPAD5    /* Rotate piece anticlockwise */
  50. #define DROP_KEY    SCANCODE_SPACE       /* Drop piece to bottom of screen */
  51. #define DOWN_KEY        SCANCODE_KEYPAD2        /* Drop piece one line */
  52. #define SUSP_KEY    KEY_P               /* Suspend.  I'm sorry if it's confusing */
  53. #define QUIT_KEY    KEY_Q               /* Quit.  I'm sorry if it's confusing */
  54.  
  55. /*--------The following are constants used internaly by the program.---------*/
  56.  
  57. #define NO_HISCORES    100    /* Size of high-score table */
  58. #define NO_SHOWN    10    /* Default number to print */
  59. #define LINELEN        160    /* Maximum length of a line of text */
  60. #define NAMELEN        24    /* Multiple of four for struct-padding */
  61. #define CODELEN        12    /* Multiple of four for struct-padding */
  62.  
  63. #define GAME_WIDTH    10    /* Number of squares across board */
  64. #define GAME_DEPTH    20    /* Number of squares down board */
  65. #define STAT_WIDTH    37    /* Number of characters for messages */
  66.  
  67. #define NO_PIECES    7    /* Number of different pieces */
  68. #define NO_ORIENTS    4    /* Number of orientations possible */
  69. #define NO_SQUARES    4    /* Max. number of squares per piece */
  70. #define NO_DIMS        2    /* Number of dimensions of screen */
  71.  
  72. #define PI_EMPTY    -1    /* Position of board is empty */
  73. #define PI_SQUARE    0    /* Square piece */
  74. #define PI_LONG        1    /* Long piece */
  75. #define PI_ELL1        2    /* L-shaped piece */
  76. #define PI_ELL2        3    /* Backwards L-shaped piece */
  77. #define PI_TEE        4    /* T-shaped piece */
  78. #define PI_ESS1        5    /* S-shaped piece */
  79. #define PI_ESS2        6    /* Backwards S-shaped piece */
  80.  
  81. /***************************************************************************\
  82. |*                                       *|
  83. |*  The following #defines, (the LE_* ones) are local errors, in the       *|
  84. |*  sense of being local to this program, as distinct from the system       *|
  85. |*  errors, (ENOENT, EINTR and friends).  They should be used as exit       *|
  86. |*  statuses, as the first argument to die(), defined in utils.c       *|
  87. |*                                       *|
  88. \***************************************************************************/
  89.  
  90. #define LE_OK        0    /* No problems, me ole' fruit-bat */
  91. #define LE_USAGE    1    /* Command-line syntax was wrong */
  92. #define LE_ENV        2    /* Couldn't get environment variable */
  93. #define LE_TERMCAP    3    /* Couldn't get a termcap entry */
  94. #define LE_SCREEN    4    /* Screen was too small for game */
  95. #define LE_SIGNAL    5    /* Signal(3) call failed */
  96. #define LE_SELECT    6    /* Select(2) call failed */
  97. #define LE_READ        7    /* Read(2) call failed */
  98. #define LE_MALLOC    8    /* Couldn't allocate memory */
  99. #define LE_LEVEL    9    /* User wanted to play on a silly level */
  100. #define LE_OPEN        10    /* Open(2) call failed */
  101. #define LE_STAT        11    /* {f,l,}stat(2) call failed */
  102. #define LE_WRITE    12    /* write(2) call failed */
  103. #define LE_GETUID    13    /* getuid(2) call failed */
  104. #define LE_GETPW    14    /* getpwuid(3) call failed */
  105.  
  106. /***************************************************************************\
  107. |*                                       *|
  108. |*  This is the structure of which the high-score table is composed.       *|
  109. |*  I'm gonna make everything a muliple of four bytes in an attempt       *|
  110. |*  to maintain file-compatibility between sun3s and 4s (and maybe       *|
  111. |*  other things, who knows?)  This is also why all the integers are       *|
  112. |*  long -- this helps to ensure that they will be four bytes long on       *|
  113. |*  most architectures, (ie. including some that have 2-byte integers)       *|
  114. |*  thus making struct-compatibility more likely.               *|
  115. |*                                       *|
  116. \***************************************************************************/
  117.  
  118. struct score_ent {
  119.   char name[NAMELEN];        /* Name of player (from environment) */
  120.   char code[CODELEN];        /* Code of player (from getpwuid()) */
  121.   long int score;        /* Total score (5 for an "S" etc.) */
  122.   long int no_pieces;        /* Number of pieces dropped in */
  123.   long int no_levels;        /* Number of levels completed */
  124.   long int game_level;        /* Number of free pieces at start */
  125. };
  126.  
  127. /*-------------------------------------------------------------------------*/
  128.  
  129. extern int screen_depth;    /* To be calculated by termcap(3) */
  130. extern int screen_width;    /* To be calculated by termcap(3) */
  131. extern int so_gunk;        /* To be calculated by termcap(3) */
  132. extern int in_curses;        /* Set to 1 after initialisation */
  133. extern int rotate_backwards;    /* If set non-zero, rotate clockwise */
  134. extern int no_hiscores;        /* Number of hi-scores in the table */
  135. extern int game_level;        /* Number of free pieces */
  136. extern int total_time;
  137. extern int score;        /* Accumulated game score */
  138. extern int no_pieces;        /* Number of pieces dropped so far */
  139. extern int no_levels;        /* Number of levels filled & deleted */
  140. extern char prog_name[LINELEN]; /* Will be the basename of argv[0] */
  141. extern char user_name[NAMELEN]; /* From environment: TTNAME or NAME */
  142. extern char user_code[CODELEN]; /* From getpwuid(getuid())->pw_name */
  143. extern int board[GAME_DEPTH+4][GAME_WIDTH];
  144. extern struct score_ent hi_scores[NO_HISCORES];
  145.  
  146. extern char tc_string[LINELEN]; /* Static, filled by termcap(3) */
  147. extern char *so_str;        /* Points at things found by termcap(3) */
  148. extern char *se_str;        /* Points at things found by termcap(3) */
  149.  
  150. /*-------------------------------------------------------------------------*/
  151.  
  152. extern void signal_die ();    /* When CTRL-C etc. is pressed */
  153.  
  154. #include <jlib.h>
  155.  
  156. extern buffer_rec *offscreen;
  157.  
  158. /*-------------------------------------------------------------------------*/
  159. /***************************************************************************\
  160. |*                                       *|
  161. |*  The following macros will be defined if FD_ZERO is not defined by       *|
  162. |*  the system.  They simulate the behaviour of 4.3bsd's FD_ macros for       *|
  163. |*  4.2bsd machines, (ie. those running Berkeley UNIX, but of earlier       *|
  164. |*  issue than 4.3; also SunOS, issues earlier than 4.0.           *|
  165. |*                                       *|
  166. |*  This section added Fri Jun 23 20:18:20 BST 1989               *|
  167. |*  Written by Mike Taylor (mirk@uk.ac.warwick.cs)               *|
  168. |*                                       *|
  169. \***************************************************************************/
  170.  
  171. #ifndef FD_ZERO
  172. #  define fd_set long int
  173. #  define FD_ZERO(fds_ptr) *(fds_ptr) = 0
  174. #  define FD_SET(fd, fds_ptr) *(fds_ptr) |= (1<<(fd))
  175. #endif /* FD_ZERO */
  176.  
  177. /*-------------------------------------------------------------------------*/
  178.